package org.example.factory03;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author liyishan
 * @date 2024/2/18 14:38
 * @apiNote
 */
@Service
public class DefaultLogic02Factory {

    public Map<String, IRuleLogicFilter> logicFilterMap = new ConcurrentHashMap<>();

    public DefaultLogic02Factory(List<IRuleLogicFilter> logicFilters) {
        logicFilters.forEach(logic -> {
            LogicStrategy strategy = AnnotationUtils.findAnnotation(logic.getClass(), LogicStrategy.class);
            if (null != strategy) {
                logicFilterMap.put(strategy.logicMode().getCode(), logic);
            }
        });
    }
    public String doFilter(String key,LogicModel... logics){
        String entity;
        for (LogicModel model : logics) {
            entity = logicFilterMap.get(model.code).filter(key);
            System.out.println(entity);
        }
        return "无匹配规则";
    }

    public enum LogicModel {

        SENSITIVE_WORD("SENSITIVE_WORD", "敏感词过滤"),
        CONTENT_SECURITY("CONTENT_SECURITY", "内容安全"),
        ;

        private String code;
        private String info;

        LogicModel(String code, String info) {
            this.code = code;
            this.info = info;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getInfo() {
            return info;
        }

        public void setInfo(String info) {
            this.info = info;
        }
    }

}
